﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Kugar.Core.Exceptions;
using Kugar.ERPFramework.BLLInterface;
using Kugar.ERPFramework.ClientBroker;
using Kugar.ERPFramework.Entity;
using Kugar.Core.ExtMethod;

namespace Kugar.ERPFramework.View.WinForm
{
    public class ClientBroker:ClientBrokerBase
    {
        private static Lazy<IClientBroker> _instance = null;

        static ClientBroker()
        {
            _instance = new Lazy<IClientBroker>(() => new ClientBroker());
        }

        public static IClientBroker GetInstance()
        {
            return _instance.Value;
        }

        public static Form MainForm { set; get; }

        public override EntityBase[] ShowDataFetcher(string dataFetcherName, bool enableMultiSelect = false, Dictionary<string, object> initValue=null)
        {
            var frm = base.GetDataFetcher(dataFetcherName);

            if (frm != null)
            {
                frm.Show(initValue);

                return frm.SelectItems;
            }
            else
                return null;
        }

        public override void ShowMessage(string msg, string caption = "")
        {
            MessageBox.Show(msg, caption);
        }

        public override bool ShowMessageWithButton(string msg, string caption = "")
        {
            if (MessageBox.Show(msg,caption,MessageBoxButtons.OKCancel)==DialogResult.OK)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public override string ShowInputBox(string caption, string msg)
        {
            return  Kugar.Core.WinForm.InputBox.ShowInputBox(caption, msg, "");
        }
    }
}
